package com.wanho.java159.code.gen.core;

import com.wanho.java159.code.gen.util.Common;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zhang
 * @version 1.0
 * @date 2021/7/10
 */
public class MapperGen {
    /**
     * 生成  po  poExample  Mapper接口  Mapper xml SQL实现
     * @throws Exception
     */
    public static void genMapperCode() throws Exception{
        System.out.println("===========生成  po  poExample  Mapper接口  Mapper xml SQL实现  开始======================");
        List<String> warnings = new ArrayList<String>();
        boolean overwrite = true;
        File configFile = new File(Common.GENERATOR_CONFIG_DIR_PATH+"generatorConfig.xml");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(configFile);
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);
        System.out.println("===========生成  po  poExample  Mapper接口  Mapper xml SQL实现  结束======================");
    }
}
